package com.example.demo.controller;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.example.demo.model.Tea;
import com.example.demo.service.TeaService;
import net.sf.jsqlparser.statement.insert.Insert;

@Controller
@RequestMapping("tea")
public class TeaController {
	@Resource
	private TeaService teaService;
	
	//增
	@RequestMapping("add")
	public String add() {
		return "tea/add";
	}
	
	@RequestMapping("insert")
	public String insert(Tea tea) {
		tea.setTeatype(tea.getTeatype());
		tea.setOrigin(tea.getOrigin());
		tea.setGrade(tea.getGrade());
		tea.setPrice(tea.getPrice());
		tea.setBrand(tea.getBrand());
		tea.setSpokesman(tea.getSpokesman());
		tea.setPicture(tea.getPicture());
		teaService.insert(tea);
		return "redirect:/tea/select";
	}
	
	//查
	@RequestMapping("select")
	public String select(Map<String,Object> map) {
		map.put("tea", teaService.select());
		return "tea/all";
	}
	
	@RequestMapping ("selectone")
	public String selectone(Map<String,Object> map,@RequestParam("id")Integer id) {
		map.put("teaone",teaService.selectone(id));
		return "tea/one";
	}
	
	//删
	@RequestMapping("delete")
	public String delete(@RequestParam("id")Integer id) {
		teaService.delete(id);
		return "redirect:/tea/select";
	}
	
	//改
	@RequestMapping("bridgeupdate")
	public String bridgeupdate(@RequestParam("id")Integer id,Tea tea,Map<String,Object> map) {
		map.put("tea", tea);
		return "tea/update";
	}
	@RequestMapping("update")
	public String update(@RequestParam("id")Integer id,Tea tea) {
		teaService.update(id,tea);
		return "redirect:/tea/select";
	}
}
